// LDCheckDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ADK.h"
#include "LDCheckDlg.h"
#include "ADKDlg.h"
#include "Opos.h"

// CLDCheckDlg dialog

IMPLEMENT_DYNAMIC(CLDCheckDlg, CDialog)

CLDCheckDlg::CLDCheckDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLDCheckDlg::IDD, pParent)
{

}

CLDCheckDlg::~CLDCheckDlg()
{
}

void CLDCheckDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LINEDISPLAY_CO, m_LD);
}

BOOL CLDCheckDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	m_LD.MoveWindow(0,0,0,0,FALSE);

	PostMessage(WM_INIT_SO, 0, 0);
	return TRUE;
}


BEGIN_MESSAGE_MAP(CLDCheckDlg, CDialog)
	ON_MESSAGE(WM_INIT_SO, &CLDCheckDlg::OnInitSO)
	ON_BN_CLICKED(IDC_BTN_EXIT, &CLDCheckDlg::OnBnClickedBtnExit)
	ON_BN_CLICKED(IDC_BTN_DISPLAY, &CLDCheckDlg::OnBnClickedBtnDisplay)
	ON_BN_CLICKED(IDC_BTN_CLEAR_TEXT, &CLDCheckDlg::OnBnClickedBtnClearText)
END_MESSAGE_MAP()


// CLDCheckDlg message handlers
LRESULT CLDCheckDlg::OnInitSO(WPARAM wParam, LPARAM lParam)
{
	if (m_LD.Open(m_strLDName) == OPOS_SUCCESS)
	{
		if (m_LD.ClaimDevice((1000)) == OPOS_SUCCESS)
		{
			// SetEnable
			m_LD.put_DeviceEnabled(TRUE);
            
		}
		else
		{
			m_LD.Close();
		}
	}
	else
	{
		MessageBox(L"Fail to open line display [" + m_strLDName + L"]  !", L"Error", MB_ICONERROR);
	}
	return S_OK;
}
void CLDCheckDlg::OnBnClickedBtnExit()
{

	m_LD.put_DeviceEnabled(FALSE);
	m_LD.ReleaseDevice();
	m_LD.Close();

	OnOK();
}

#include "OposDisp.h"
void CLDCheckDlg::OnBnClickedBtnDisplay()
{
	CString strText1, strText2;
	CDialog::GetDlgItemTextW(IDC_EDIT_1ST_TEXT, strText1);
	CDialog::GetDlgItemTextW(IDC_EDIT_2ND_TEXT, strText2);

	m_LD.DisplayTextAt(0, 0, strText1, DISP_DT_NORMAL);
	m_LD.DisplayTextAt(1, 0, strText2, DISP_DT_NORMAL);
}

void CLDCheckDlg::OnBnClickedBtnClearText()
{
	m_LD.ClearText();
}
